package role

import (
	"fmt"
	"parking-lot-go-admin/controller"
	"parking-lot-go-admin/model"
	"parking-lot-go-admin/model/admin"

	"github.com/gin-gonic/gin"
)

func UpdateStatus(c *gin.Context) {
	requestDataStruct := struct {
		Id     int `json:"id"`
		Status int `json:"status"`
	}{}

	c.ShouldBindJSON(&requestDataStruct)

	var adminGroupStruct admin.AdminGroupStruct
	if err := model.UpdateModelData(
		model.Db,
		adminGroupStruct.TableName(),
		map[string]interface{}{
			"id": requestDataStruct.Id,
		},
		map[string]interface{}{
			"status": requestDataStruct.Status,
		}); err != nil {
		controller.Fail(c, fmt.Sprintf("修改角色状态失败%s", err.Error()))
		return
	}

	controller.Success(c, "")
}
